package com.twang.stock.service.jinyan;

import com.twang.stock.entity.StockMoneyIn;
import com.twang.stock.mapper.StockMoneyInMapper;
import com.twang.stock.task.old.StockMoneyInTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * 获取资金流入情况
 */
@Slf4j
@Service
public class StockMoneyInListService {
    @Resource
    private StockMoneyInMapper stockMoneyInMapper;
    @Resource
    private StockMoneyInTask stockMoneyInTask;

    public List<StockMoneyIn> getMoneyInByStockName(String stockName) throws Exception {
        //先查一遍
      // stockMoneyInTask.moneyInHistory(stockName);
        //
        Example example = new Example(StockMoneyIn.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stockName", stockName);
        example.orderBy("date").asc();
        List<StockMoneyIn> list=  stockMoneyInMapper.selectByExample(example);
        BigDecimal amount=BigDecimal.ZERO;
        if(!CollectionUtils.isEmpty(list)){
           // amount=list.get(0).getTd3();
            for (StockMoneyIn item:list) {
                amount=amount.add(item.getTd3());
                item.setTotoalAmount(amount);
            }
        }
        return list;
    }

}
